package com.log.james.mapper;

import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * 异常的dao层
 */
@Mapper
public interface AbnormalDao {

    /**
     * 选取指定条数
     * 目的IP访问异常
     * @param st
     * @param et
     * @param num
     * @return
     */
    @Select("select * from destipanalysis where starttime >= #{st} and endtime <= #{et} and isattack = 1 order by starttime desc limit 0,#{num}")
    List<Map<String,Object>> findIpAbnormal(@Param("st")Date st,@Param("et")Date et,@Param("num")int num);

    /**
     * 找出该时间段内的所有的IP异常
     * 下同
     * @param st
     * @param et
     * @return
     */
    @Select("select * from destipanalysis where starttime >= #{st} and endtime <= #{et} and isattack = 1 order by starttime desc")
    List<Map<String,Object>> findAllIpAbnormal(@Param("st")Date st,@Param("et")Date et);

    /**
     * 端口访问异常
     * @param st
     * @param et
     * @param num
     * @return
     */
    @Select("select * from destportscananlysis where starttime >= #{st} and endtime <= #{et} and isattack = 1 order by starttime desc limit 0,#{num}")
    List<Map<String,Object>> findPortAbnormal(@Param("st")Date st,@Param("et")Date et,@Param("num")int num);

    @Select("select * from destportscananlysis where starttime >= #{st} and endtime <= #{et} and isattack = 1 order by starttime desc")
    List<Map<String,Object>> findAllPortAbnormal(@Param("st")Date st,@Param("et")Date et);

    /**
     * 防火墙流量异常
     * @param st
     * @param et
     * @param num
     * @return
     */
    @Select("select * from fwlogflow where starttime >= #{st} and endtime <= #{et} and abnormal = 1 order by starttime limit 0,#{num}")
    List<Map<String,Object>> findFireWallStreamAbnormal(@Param("st")Date st,@Param("et")Date et,@Param("num")int num);

    @Select("select * from fwlogflow where starttime >= #{st} and endtime <= #{et} and abnormal = 1 order by starttime")
    List<Map<String,Object>> findAllFireWallStreamAbnormal(@Param("st")Date st,@Param("et")Date et);

    /**
     * web服务器流量异常
     * @param st
     * @param et
     * @param num
     * @return
     */
    @Select("select * from weblogflow where starttime >= #{st} and endtime <= #{et} and abnormal = 1 order by starttime limit 0,#{num}")
    List<Map<String,Object>> findWebStreamAbnormal(@Param("st")Date st,@Param("et")Date et,@Param("num")int num);

    @Select("select * from weblogflow where starttime >= #{st} and endtime <= #{et} and abnormal = 1 order by starttime ")
    List<Map<String,Object>> findAllWebStreamAbnormal(@Param("st")Date st,@Param("et")Date et);

    /**
     * 访客异常
     * @param st
     * @param et
     * @param num
     * @return
     */
    @Select("select * from srcipscananalysis where starttime >= #{st} and endtime <= #{et} ORDER BY starttime desc limit 0,#{num}")
    List<Map<String,Object>> findVisitorAbnormal(@Param("st")Date st,@Param("et")Date et,@Param("num")int num);

    @Select("select * from srcipscananalysis where starttime >= #{st} and endtime <= #{et} ORDER BY starttime desc")
    List<Map<String,Object>> findAllVisitorAbnormal(@Param("st")Date st,@Param("et")Date et);
}
